using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Chili.Opf3.Wizard.Shared;
using Chili.Opf3.Wizard.Shared.Storages;
using Chili.Opf3.Wizard.SimplePlugin.Properties;

namespace Chili.Opf3.Wizard.SimplePlugin
{
	/// <summary>
	/// This class represents a page that is shown for the sample plug-in.
	/// </summary>
	public partial class SamplePage : Chili.Opf3.Wizard.Shared.UI.Page
	{
		private StateBag _statebag;

		/// <summary>
		/// Creates a new instance of the <see cref="SamplePage">SamplePage Class</see>.
		/// </summary>
		/// <param name="provider">The provider itself.</param>
		/// <param name="statebag">The statebag holding the data of the plug-in.</param>
		public SamplePage(SampleProvider provider, StateBag statebag)
			: base(provider)
		{
			InitializeComponent();

			if (provider == null)
				throw new ArgumentNullException("provider", "Provider is null.");
			if (statebag == null)
				throw new ArgumentNullException("statebag", "StateBag is null.");

			_statebag = statebag;
		}

		/// <summary>
		/// Invoked each time the page is opened.
		/// </summary>
		/// <param name="project">The current project.</param>
		public override void PageOpening(Project project)
		{
			nameTextBox.Text = _statebag.Name;
		}

		/// <summary>
		/// Invoked each time the page is closed.
		/// </summary>
		/// <param name="next">True if the next button has been clicked. False on all other.</param>
		public override bool PageClosing(bool next)
		{
			// If not next has been clicked, just skip this here.
			if (!next)
				return true;

			// Check if the name text box contains valid data.
			if (nameTextBox.Text.Length == 0)
			{
				// Show a message box if not.
				MessageBox.Show(Resources.MissingNameText, Resources.MissingNameTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
				nameTextBox.Focus();
				// Return false to valid switching to the next page.
				return false;
			}

			_statebag.Name = nameTextBox.Text;

			return true;
		}
	}
}
